package tank;

import java.awt.*;
import java.awt.image.BufferedImage;

/**
 * @Auther: fei
 * @Date: 2021/6/16 - 06 - 16 - 20:30
 * @Description: tank
 * @version: 1.0
 */

//用旋转来控制图片
public class ImageUtil {
    public static BufferedImage rotateImage(final BufferedImage bufferedImage,
                                            final int degree){
        int w = bufferedImage.getWidth();
        int h = bufferedImage.getHeight();
        int type = bufferedImage.getColorModel().getTransparency();
        BufferedImage img;
        Graphics2D graphics2d;
        (graphics2d = (img = new BufferedImage(w, h, type)).createGraphics()).setRenderingHint(
                RenderingHints.KEY_INTERPOLATION,
                RenderingHints.VALUE_INTERPOLATION_BILINEAR);
        graphics2d.rotate(Math.toRadians(degree),w/2,h/2);
        graphics2d.drawImage(bufferedImage,0,0,null);
        graphics2d.dispose();
        return img;
    }
}
